package com.ebelter.test01.module.dj8module;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import com.ebelter.test01.R;

import java.util.List;

public class PacaActivity extends Activity {

    TextView tv1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_paca);
        tv1=findViewById(R.id.tv1);


        Intent intent = new Intent(Intent.ACTION_MAIN, null);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        List<ResolveInfo> apps = getPackageManager().queryIntentActivities(intent, 0);
        //for循环遍历ResolveInfo对象获取包名和类名
        StringBuilder sb=new StringBuilder();
        for (int i = 0; i < apps.size(); i++) {
            ResolveInfo info = apps.get(i);
            String packageName = info.activityInfo.packageName;
            CharSequence cls = info.activityInfo.name;
            CharSequence name = info.activityInfo.loadLabel(getPackageManager());
            //Log.e("！！！！！", name + "----" + packageName + "----" + cls);
            sb.append("应用名："+name).append("\n").append("包名："+cls).append("\n\n");
        }

        tv1.setText(sb.toString());
    }
}
